﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Data.Models;

namespace Parafarmacia.UserControls
{
    public partial class UserLogin : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void butSummit_Click(object sender, EventArgs e)
        {
            Summit();
        }

        /// <summary>
        /// Login. check user and password
        /// </summary>
        private void Summit()
        {
            using (var db = new dbParafarmaciaContext())
            {
                if (txtUser.Text == db.tblEmpresaInfos.FirstOrDefault().Login && txtPass.Text == db.tblEmpresaInfos.FirstOrDefault().Password)
                {
                    Response.Redirect("ControlPanel.aspx", false);
                }
                else
                {
                    ErrorLiteral.Text = "Nombre de usuario o contraseña invalidos. Por favor, vuelva a intentarlo.";
                    txtUser.Text = "";
                    txtPass.Text = "";
                    txtUser.Focus();
                }
            }
        }
    }
}